//
//  AFN.m
//  Custom
//
//  Created by dllo on 15/11/26.
//  Copyright © 2015年 KPY. All rights reserved.
//

#import "AFN.h"

@implementation AFN

+ (void)GETDataWithURL:(NSString *)url block:(responseObject)result {
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    [manager GET:url parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        result(responseObject);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"%@", error);
        
    }];
    
}

+ (void)POSTDataWithURL:(NSString *)url POST:(NSDictionary *)dic block:(responseObject)result {
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    [manager POST:url parameters:dic success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        result(responseObject);
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"%@", error);
        
    }];

    
}

+ (void)showNetWorkStatus:(netWorkStatus)result
{
    AFNetworkReachabilityManager *manager =  [AFNetworkReachabilityManager sharedManager];
    [manager startMonitoring];
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        
        NSString *str;
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:
                str = @"未知网络";
//                [self.hud removeFromSuperview];
                break;
            case AFNetworkReachabilityStatusNotReachable:
                str = @"网络未连接";
                
//                [self.hud removeFromSuperview];
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                str = @"网络已连接";
//                [self createData];
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi:
                str = @"WiFi已连接";
//                [self createData];
                break;
            default:
                break;
        }
        result(str);
    }];
    
}

@end
